package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.EverydayWelfare;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/12 10:56
 */
public class EverydayWelfareAdapter extends BaseRecyclerAdapter<EverydayWelfareAdapter.Holder, EverydayWelfare> {
    private final String TAG = "EverydayWelfareAdapter";


    public EverydayWelfareAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_everyday_welfare;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        final int index = position;
        EverydayWelfare entity = data.get(position);
        holder.numTv.setText("" + (position + 1));
        holder.contentTv.setText(entity.getTaskDescribe());
        holder.moneyTv.setText("+" + entity.getTaskMoney() + "元");
        holder.progressbar.setMax(entity.getStagePurpose());
        holder.progressbar.setProgress(entity.getProgress());
        holder.progressTv.setText(entity.getProgress() + "/" + entity.getStagePurpose());
        switch (entity.getIsOver()) {
            case 0:
                holder.buttonTv.setEnabled(true);
                holder.buttonTv.setText("去完成");
                break;
            case 1:
                holder.buttonTv.setEnabled(true);
                holder.buttonTv.setText("领取");
                break;
            case 2:
                holder.buttonTv.setText("已领取");
                holder.buttonTv.setEnabled(false);
                break;
        }
        holder.buttonTv.setOnClickListener(v -> {
            if (itemClickListener != null) {
                itemClickListener.onViewClick(v, entity.getIsOver() == 1 ? "领取" : "去完成", index, entity);
            }
        });
    }


    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.num_tv)
        TextView numTv;
        @BindView(R.id.content_tv)
        TextView contentTv;
        @BindView(R.id.money_tv)
        TextView moneyTv;
        @BindView(R.id.progressbar)
        ProgressBar progressbar;
        @BindView(R.id.progress_tv)
        TextView progressTv;
        @BindView(R.id.button_tv)
        TextView buttonTv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
